package com.matrix.java.chap_06;

/*
    梅森素数
 */
public class Ex6_28 {
    public static void main(String[] args) {
        System.out.println("p\t\t2^p-1");
        for (int i = 2; i <= 31; i++) {
            int num = (int) (Math.pow(2, i) - 1);
            if (isPrime(num)) {
                System.out.println(i + "\t\t" + num);
            }
        }
    }

    private static boolean isPrime(int num) {
        boolean isPrime = true;
        for (int i = 2; i < num; i++) {
            if (num % i == 0) {
                isPrime = false;
                break;
            }
        }
        return isPrime;
    }
}
